home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11141 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news2.noc.netcom.net!news
  2. From: Tarang Deshpande <tarang@willows.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q about the float point format......
  5. Date: Tue, 19 Mar 1996 16:45:29 -0800
  6. Organization: NETCOM Network Operations
  7. Message-ID: <314F5529.112@willows.com>
  8. References: <s3032089.15.314E68DD@sparc13.ncu.edu.tw>
  9. NNTP-Posting-Host: daffy.willows.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  14.  
  15. Alexander PeaceLand wrote:
  16. >    Could I dynamicly set the digits after the float POINT?
  17. >    In other word... I use printf to print the float point number
  18. >                     like 123.456789 but in the other time i only
  19. >                     want to print 123.456 or 123.4
  20.  
  21.  
  22. You can actually specify the field width and the number of decimals by
  23. using printf ( "%*.*f", Width, Decimals, FloatNumber ); where, Width
  24. is an int that specifies the total width of the field, Decimals is
  25. also an int that specifies the number of dicimal places that are to
  26. be printed, and FloatNumber is the actual value you wish to print.
  27.  
  28. If Width is negative then the print out is left justified rather than
  29. right.  If width is left out then the width becomes whatever is 
  30. necessary to print the value.  You can also use 0* to mean zero fill
  31. blank spaces.
  32.